package com.ufsoft.iufo.fmtplugin.formula;

import nc.ui.ntb.outer.itf.AbstractNtbRefPane;
import nc.ui.ntb.outer.itf.INtbRefObject;
import nc.ui.ntb.outer.itf.NtbRefClassLoader;
import nc.ui.pub.beans.UIDialog;

public class NtbFunctionRefCaller implements INtbFunctionRefCaller {

	private String refType = null;
	private AbstractNtbRefPane ntbRef = null;
	
	public String[] doFuncRefer(String refType) {
		if (refType != null && !refType.equals(this.refType)) {
			ntbRef = null;
			this.refType = refType;
		}
		int rtn = getNtbRefPane().executeButtonClick(null);
		if (rtn == UIDialog.ID_OK) {
			INtbRefObject obj = getNtbRefPane().getSelectedRefObject();
			if (obj != null) {
				return obj.getParams();
			}
		}
		return null;
	}
	
	private AbstractNtbRefPane getNtbRefPane() {
		if (ntbRef == null) {
			ntbRef = NtbRefClassLoader.getNtbRefNewInstance(refType);
		}
		return ntbRef;
	}
}
